from enum import Enum
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
import os


class BrowserType(str, Enum):
    CHROME = "chrome"
    FIREFOX = "firefox"
    EDGE = "edge"
    SAFARI = "safari"


class BrowserFactory:
    @staticmethod
    def create_browser(
        browser_type: BrowserType, headless: bool = False, options=None
    ) -> WebDriver:
        if options is None:
            options = {}

        match browser_type:
            case BrowserType.CHROME:
                chrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument('--disable-infobars')
                chrome_options.add_argument('--disable-notifications')

                if headless:
                    chrome_options.add_argument('--headless=new')
                    chrome_options.add_argument('--window-size=1920x1080')

                for opt in options.get('chrome', []):
                    chrome_options.add_argument(opt)

                return webdriver.Chrome(
                    service=ChromeService(ChromeDriverManager().install()),
                    options=chrome_options,
                )

        raise ValueError(f'Unsupported browser type: {browser_type}')
